package com.dianxin.secure.persist;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class RedieDaoHandler implements InvocationHandler {
	private Log log = LogFactory.getLog(getClass());
	private static RedisStore redisStore = new RedisStore();
	
	private Object target = null;

	RedieDaoHandler(Object target) {
		this.target = target;
	}

	public Object invoke(Object proxy, Method method, Object[] args)
			 {
		Object result = null;
		try {
			RedisDao.jedis=redisStore.borrowJedis();
			result = method.invoke(target, args);
		}
//		catch (JedisConnectionException e) {
//            redisStore.returnBrokenJedis(RedisDao.jedis);
//            log.error(e);
//            throw e;
//        }
        catch(Exception e){
            e.printStackTrace();
            log.error(e);
        }
        finally {
            redisStore.returnJedis(RedisDao.jedis);
        }
		return result;
	}
}
